package com.agricultureaigclargemodel.history.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.agricultureaigclargemodel.common.annotation.Log;
import com.agricultureaigclargemodel.common.core.controller.BaseController;
import com.agricultureaigclargemodel.common.core.domain.AjaxResult;
import com.agricultureaigclargemodel.common.enums.BusinessType;
import com.agricultureaigclargemodel.history.domain.ChatHistory;
import com.agricultureaigclargemodel.history.service.IChatHistoryService;
import com.agricultureaigclargemodel.common.utils.poi.ExcelUtil;
import com.agricultureaigclargemodel.common.core.page.TableDataInfo;

/**
 * 聊天历史记录Controller
 * 
 * @author Evanescent
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/history/history")
public class ChatHistoryController extends BaseController
{
    @Autowired
    private IChatHistoryService chatHistoryService;

    /**
     * 查询聊天历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('history:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatHistory chatHistory)
    {
        startPage();
        List<ChatHistory> list = chatHistoryService.selectChatHistoryList(chatHistory);
        return getDataTable(list);
    }

    /**
     * 导出聊天历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('history:history:export')")
    @Log(title = "聊天历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChatHistory chatHistory)
    {
        List<ChatHistory> list = chatHistoryService.selectChatHistoryList(chatHistory);
        ExcelUtil<ChatHistory> util = new ExcelUtil<ChatHistory>(ChatHistory.class);
        util.exportExcel(response, list, "聊天历史记录数据");
    }

    /**
     * 获取聊天历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('history:history:query')")
    @GetMapping(value = "/{chatId}")
    public AjaxResult getInfo(@PathVariable("chatId") String chatId)
    {
        return success(chatHistoryService.selectChatHistoryByChatId(chatId));
    }

    /**
     * 新增聊天历史记录
     */
    @PreAuthorize("@ss.hasPermi('history:history:add')")
    @Log(title = "聊天历史记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatHistory chatHistory)
    {
        return toAjax(chatHistoryService.insertChatHistory(chatHistory));
    }

    /**
     * 修改聊天历史记录
     */
    @PreAuthorize("@ss.hasPermi('history:history:edit')")
    @Log(title = "聊天历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatHistory chatHistory)
    {
        return toAjax(chatHistoryService.updateChatHistory(chatHistory));
    }

    /**
     * 删除聊天历史记录
     */
    @PreAuthorize("@ss.hasPermi('history:history:remove')")
    @Log(title = "聊天历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chatIds}")
    public AjaxResult remove(@PathVariable String[] chatIds)
    {
        return toAjax(chatHistoryService.deleteChatHistoryByChatIds(chatIds));
    }
}
